package com.ruibei.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.ruibei.R;
import com.ruibei.models.ApprovalDetailModel;
import com.ruibei.view.TitleBarView;
/**
 * 添加审批明细页面
 * @author wu
 *
 */
public class AddApprovalDetailActivity extends BaseActivity{
	
	@InjectView(R.id.add_approval_detail)
	TitleBarView add_approval_detail_title_bar;
	@InjectView(R.id.goods)
	EditText goods;
	@InjectView(R.id.count)
	EditText count;
	@InjectView(R.id.estimated_amount)
	EditText estimated_amount;
	@InjectView(R.id.remark)
	EditText remark;
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_detail_for_apporval);
		ButterKnife.inject(this);
		initView();
	}


	private void initView() {
		// TODO Auto-generated method stub
		add_approval_detail_title_bar.setTitleText(R.string.add_approval_detail_title);
		add_approval_detail_title_bar.setBtnLeft(R.drawable.back, R.string.back);
		add_approval_detail_title_bar.setCommonTitle(View.VISIBLE, View.VISIBLE, View.VISIBLE);
		add_approval_detail_title_bar.setBtnLeftOnclickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		add_approval_detail_title_bar.setBtnRightText(R.string.save);
		add_approval_detail_title_bar.setBtnRightOnclickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
				if(goods.getText().toString().trim().equals("")||count.getText().toString().trim().equals("")
						||estimated_amount.getText().toString().trim().equals("")){
					Toast.makeText(AddApprovalDetailActivity.this, "必填信息不能为空", Toast.LENGTH_LONG).show();
					return;
				}
				ApprovalDetailModel approvalDetailModel = new ApprovalDetailModel();
				approvalDetailModel.setGoods(goods.getText().toString().trim());
				approvalDetailModel.setEstimated_amount(estimated_amount.getText().toString().trim());
				approvalDetailModel.setCount(count.getText().toString().trim());
				approvalDetailModel.setRemark(remark.getText().toString().trim());
				Intent data=new Intent(); 
				data.putExtra("approval_data", approvalDetailModel);
				setResult(100, data);
				finish();
			}
		});
	}

}
